package leetcode.easy;

import java.util.LinkedList;
import java.util.List;

import leetcode.base.TreeNode;

public class $257_BinaryTreePaths {
    List<String> res = new LinkedList<>();

    List<String> path = new LinkedList<>();

    public List<String> binaryTreePaths(TreeNode root) {
        dfs(root);
        return res;
    }

    public void dfs(TreeNode root) {
        if(root.left == null && root.right == null) {
            path.add(String.valueOf(root.val));
            res.add(String.join("->", path));
            path.remove(path.size() - 1);
            return ;
        }
        path.add(String.valueOf(root.val));
        if (root.left != null) {
            dfs(root.left);
        }
        if (root.right != null) {
            dfs(root.right);
        }
        path.remove(path.size() - 1);
    }
}
